int** matrixReshape(int** mat, int matSize, int* matColSize, int r, int c, int* returnSize, int** returnColumnSizes){
    int total = 0;
    for (int i = 0; i < matSize; i++) {
        total += matColSize[i];
    }
    if (total != r*c) {
        *returnSize = matSize;
        *returnColumnSizes = matColSize;
        return mat;
    }
    int* tmp = (int*)malloc(sizeof(int)*total);
    int i = 0;
    for (int y = 0; y < matSize; y++) {
        for (int x = 0; x < matColSize[y]; x++) {
            tmp[i] = mat[y][x];
            i++;
        }
    }
    *returnSize = r;
    int** res = (int**)malloc(sizeof(int*)*r);
    *returnColumnSizes = (int*)malloc(sizeof(int)*r);
    for (int y = 0; y < r; y++) {
        res[y] = (int*)malloc(sizeof(int)*c);
        (*returnColumnSizes)[y] = c;
        for (int x = 0; x < c; x++) {
            res[y][x] = tmp[y*c+x];
        }
    }
    free(tmp);
    return res;
}
